/**
 * Copyright (C) 2017 - 2020 https://github.com/joewee
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.game.service;

import com.bifrost.game.entity.LotteryAward;
import com.bifrost.game.entity.LotteryGame;
import com.bifrost.game.entity.LotteryGameAward;
import com.bifrost.game.entity.LotteryGameWinner;
import com.bifrost.game.exception.LotteryUnavailableException;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 抽奖游戏服务
 *
 * @author joewee
 * @version 1.0.0
 * @Date 2018/5/9 10:36
 */
public interface LotteryGameService {

    /**
     * 查询对应门店的所有有效活动
     *
     * @param merchanId
     * @return
     */
    List<LotteryGame> findGamesByMerchant(Long merchanId);

    /**
     * 根据uid查询抽奖游戏
     *
     * @param uid
     * @return
     */
    LotteryGame findByUid(String uid);
    LotteryGame findId(Long uid);

    /**
     * 根据id查询抽奖游戏
     *
     * @param id
     * @return
     */
    LotteryGame findById(Long id);


    /**
     * 参与抽奖
     * @param game
     * @return
     */
    int attendLotteryGame(LotteryGame game);

    /**
     * 抽奖
     * <p>若中奖则返回LotteryGameWinner抽奖结果，未中奖则为null</p>
     *
     * @param customerId 用户标识
     * @param uid        抽奖游戏uid
     * @return
     * @throws LotteryUnavailableException
     */
    LotteryGameWinner draw(String customerId, Long uid) throws LotteryUnavailableException;


    /**
     * 记录中奖信息并扣减奖品库存
     * @param game
     * @param customerId
     * @param lotteryGameAward
     * @return LotteryGameWinner
     */
    LotteryGameWinner writeWinnerLog(LotteryGame game, String customerId, LotteryGameAward lotteryGameAward);

    LotteryGameAward findLotteryGameAward(LotteryGame game, LotteryAward award);
}
